本文描述了如何通过三个沙盒msyql实例,创建一个Single-Primary Innodb cluster,并通过mysql Router对connections实现路由,实现高可用性。
This section explains how to set up a single-primary InnoDB cluster and configure MySQL Router to achieve high availability.
This tutorial shows how to use MySQL Shell to create an InnoDB cluster consisting of a MySQL Server instance which provides the seed instance of the InnoDB cluster and holds the initial data set. Two more sandbox MySQL server instances are created and added to the InnoDB cluster. Then MySQL Router is deployed and used to route connections to the InnoDB cluster, and high availability is tested.
1. Yum 安装MySQL Shell
|
|
2. 创建三个沙盒实例
Start MySQL Shell
|
|
MySQL Shell provides two scripting languages: JavaScript and Python. Throughout this guide MySQL Shell is used primarily in JavaScript mode . When MySQL Shell starts it is in JavaScript mode by default. You switch into JavaScript mode, Python mode and SQL mode using the commands \js
, \py
, and \sql
. Ensure you are in JavaScript mode by issuing the \js
command, then execute:
|
|
3. Creating the InnoDB Cluster
Connect MySQL Shell to the seed instance, in this case the one at port 3310:
|
|
Use the createCluster()
method to create the InnoDB cluster with the currently connected instance as the seed:
|
|
4. Adding Instances to an InnoDB Cluster
配置/etc/hosts
|
|
Obtaining the cluster
Instance Variable
|
|
Add the second instance to the InnoDB cluster:
|
|
Add the third instance:
|
|
查看cluster 状态
|
|
5. 安装配置 MySQL Router
Yum安装
|
|
bootstrap 生成配置文件
|
|
配置文件/etc/mysqlrouter/mysqlrouter.conf
内容
|
|
启动mysqlrouter(记得修改下权限 默认权限不对)
|
|
测试连接
|
|
6. Testing Failover
killing the PRIMARY
instance 3310
|
|
测试连接(第一次失败,第二次成功)
|
|
查看cluster状态, 可以发现3320实例已经变成Primary
|
|
bring the instance that you killed back online.
|
|
重新查看cluster状态
|
|